home *** CD-ROM | disk | FTP | other *** search
/ Champak 125 / Vol 125 (Damaged).iso / games / rabbit_r.swf / scripts / __Packages / smashing / Point3D.as < prev   
Encoding:
Text File  |  2009-06-09  |  4.0 KB  |  186 lines

  1. class smashing.Point3D
  2. {
  3.    var x;
  4.    var y;
  5.    var z;
  6.    function Point3D(x, y, z)
  7.    {
  8.       this.x = Number(x);
  9.       this.y = Number(y);
  10.       this.z = Number(z);
  11.    }
  12.    function get length()
  13.    {
  14.       return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  15.    }
  16.    function set length(newLength)
  17.    {
  18.       if(this.length != 0)
  19.       {
  20.          var _loc2_ = newLength / this.length;
  21.          this.x *= _loc2_;
  22.          this.y *= _loc2_;
  23.          this.z *= _loc2_;
  24.       }
  25.    }
  26.    function get lengthSqu()
  27.    {
  28.       return this.x * this.x + this.y * this.y + this.z * this.z;
  29.    }
  30.    function copy()
  31.    {
  32.       return new smashing.Point3D(this.x,this.y,this.z);
  33.    }
  34.    function addPoint(p)
  35.    {
  36.       return new smashing.Point3D(p.x + this.x,p.y + this.y,p.z + this.z);
  37.    }
  38.    function subtractPoint(p)
  39.    {
  40.       return new smashing.Point3D(this.x - p.x,this.y - p.y,this.z - p.z);
  41.    }
  42.    function addScalar(n)
  43.    {
  44.       return new smashing.Point3D(this.x + n,this.y + n,this.z + n);
  45.    }
  46.    function subtractScalar(n)
  47.    {
  48.       return new smashing.Point3D(this.x - n,this.y - n,this.z - n);
  49.    }
  50.    function addPointMe(p)
  51.    {
  52.       this.x += p.x;
  53.       this.y += p.y;
  54.       this.z += p.z;
  55.    }
  56.    function subtractPointMe(p)
  57.    {
  58.       this.x -= p.x;
  59.       this.y -= p.y;
  60.       this.z -= p.z;
  61.    }
  62.    function addScalarMe(n)
  63.    {
  64.       this.x += n;
  65.       this.y += n;
  66.       this.z += n;
  67.    }
  68.    function subtractScalarMe(n)
  69.    {
  70.       this.x -= n;
  71.       this.y -= n;
  72.       this.z -= n;
  73.    }
  74.    function multiply(n)
  75.    {
  76.       var _loc2_ = this.copy();
  77.       _loc2_.x *= n;
  78.       _loc2_.y *= n;
  79.       _loc2_.z *= n;
  80.       return _loc2_;
  81.    }
  82.    function divide(n)
  83.    {
  84.       var _loc2_ = this.copy();
  85.       if(n == 0)
  86.       {
  87.          _loc2_.x = 0;
  88.          _loc2_.y = 0;
  89.          _loc2_.z = 0;
  90.          return undefined;
  91.       }
  92.       _loc2_.x /= n;
  93.       _loc2_.y /= n;
  94.       _loc2_.z /= n;
  95.       return _loc2_;
  96.    }
  97.    function multiplyMe(n)
  98.    {
  99.       this.x *= n;
  100.       this.y *= n;
  101.       this.z *= n;
  102.    }
  103.    function divideMe(n)
  104.    {
  105.       this.x /= n;
  106.       this.y /= n;
  107.       this.z /= n;
  108.    }
  109.    function dot(p)
  110.    {
  111.       return this.x * p.x + this.y * p.y + this.z * p.z;
  112.    }
  113.    function cross(p)
  114.    {
  115.       return new smashing.Point3D(this.y * p.z - this.z * p.y,this.z * p.x - this.x * p.z,this.x * p.y - this.y * p.x);
  116.    }
  117.    function pseudoCross()
  118.    {
  119.       return new smashing.Point3D(this.y,- this.x,this.z);
  120.    }
  121.    function normalize()
  122.    {
  123.       if(!this.x && !this.y && !this.z)
  124.       {
  125.          return undefined;
  126.       }
  127.       var _loc2_ = this.length;
  128.       return new smashing.Point3D(this.x / _loc2_,this.y / _loc2_,this.z / _loc2_);
  129.    }
  130.    function normalizeMe()
  131.    {
  132.       if(!this.x && !this.y)
  133.       {
  134.          return undefined;
  135.       }
  136.       var _loc2_ = this.length;
  137.       this.x /= _loc2_;
  138.       this.y /= _loc2_;
  139.       this.z /= _loc2_;
  140.    }
  141.    function reverse()
  142.    {
  143.       var _loc2_ = new smashing.Point3D(this.x * -1,this.y * -1,this.z * -1);
  144.       return _loc2_;
  145.    }
  146.    function reverseMe()
  147.    {
  148.       this.x *= -1;
  149.       this.y *= -1;
  150.       this.z *= -1;
  151.    }
  152.    function findCosine(vOther)
  153.    {
  154.       var _loc3_ = this.dot(vOther);
  155.       var _loc4_ = this.length * vOther.length;
  156.       var _loc2_ = _loc3_ / _loc4_;
  157.       return _loc2_;
  158.    }
  159.    function equals(p)
  160.    {
  161.       if(this.x == p.x && this.y == p.y && this.z == p.z)
  162.       {
  163.          return true;
  164.       }
  165.       return false;
  166.    }
  167.    function zero()
  168.    {
  169.       this.x = 0;
  170.       this.y = 0;
  171.       this.z = 0;
  172.    }
  173.    function distSqu(p)
  174.    {
  175.       var _loc4_ = p.x - this.x;
  176.       var _loc3_ = p.y - this.y;
  177.       var _loc2_ = p.z - this.z;
  178.       return _loc4_ * _loc4_ + _loc3_ * _loc3_ + _loc2_ * _loc2_;
  179.    }
  180.    function toString()
  181.    {
  182.       var _loc2_ = "Point3D (" + this.x + "," + this.y + "," + this.z + ")";
  183.       return _loc2_;
  184.    }
  185. }
  186.